<template>
	<view class="">
		<div v-if="gjp">
			<u-skeleton :loading="true" :animate="true" rows="7"  rowsHeight="100"></u-skeleton>
		</div>
		<div class="compareBox" v-else>
			<div class="content">
				<div class="contentBox">
					<div class="items">
						<div class="item thead">
							<div class="th">年份</div>
							<div class="th">公告来源</div>
							<div class="th">职位名称</div>
							<div class="th">职位代码</div>
							<div class="th">招考人数</div>
							<div class="th">缴费人数</div>
							<div class="th">竞争比</div>
							<div class="th">职位性质</div>
							<div class="th">地区</div>
							<div class="th">所属系统</div>
							<div class="th">部门名称</div>
							<div class="th">部门代码</div>
							<div class="th">用人处（科）室</div>
							<div class="th">招考对象</div>
							<div class="th">学历</div>
							<div class="th">专业</div>
							<div class="th">工作经历</div>
							<div class="th">政治面貌</div>
							<div class="th">岗位最低服务年限</div>
							<div class="th">其他信息</div>
						</div>
						<div class="overBox">
							<div class="flexBox">
								<div class="item tbody" v-for="(item,index) in zwDetail" :key="index">
									<div class="td" @click="showToast('default' ,item.year)">{{ item.year ? item.year : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.ggxx)">{{ item.ggxx ? item.ggxx : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.zwmc)">{{ item.zwmc ? item.zwmc : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.zwdm)">{{ item.zwdm ? item.zwdm : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.zkrs)">{{ item.zkrs ? item.zkrs : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.jfrs)">{{ item.jfrs ? item.jfrs : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.jzb)">{{ item.jfrs ? showJzb(item.jfrs,item.zkrs) : 0 }}</div>
									<div class="td" @click="showToast('default' ,item.zwxz)">{{ item.zwxz ? item.zwxz : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.city)">{{ item.city ? item.city : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.xt)">{{ item.xt ? item.xt : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.bmmc)">{{ item.bmmc ? item.bmmc : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.bmdm)">{{ item.bmdm ? item.bmdm : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.yrcs)">{{ item.yrcs ? item.yrcs : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.zkdx)">{{ item.zkdx ? item.zkdx : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.xl)">{{ item.xl ? item.xl : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.zy)">{{ item.zy ? item.zy : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.gzjl)">{{ item.gzjl ? item.gzjl : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.zzmm)">{{ item.zzmm ? item.zzmm : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.fwnx)">{{ item.fwnx ? item.fwnx : '无' }}</div>
									<div class="td" @click="showToast('default' ,item.bz)">{{ item.bz ? item.bz : '无' }}</div>
								</div>
							</div>
						</div>
					</div>
					
				</div>
			</div>
		</div>
		
		
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		mapActions
	} from 'vuex';
	export default {
		data() {
			return {
				gjp: true,
				year: "2022",
				wyz: "",
				zwLink: "https://hlj.offcn.com/zg/lynn/sk-tools/zwb2022.js",
				linkList: [
					{year: "2023", link: "https://hlj.offcn.com/zg/lynn/sk-tools/zwb2023.js"},
					{year: "2022", link: "https://hlj.offcn.com/zg/lynn/sk-tools/zwb2022.js"},
					{year: "2021", link: "https://hlj.offcn.com/zg/lynn/sk-tools/zwb2022.js"}
				],
				zwDetail: []
			};
		},
		onShow() {},
		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onPageScroll(e) {
			let that = this;
		},
		onLoad(options) {
			if (!options) {} else {
				
			}
		},
		computed: {
			favzw() {
				return this.$store.getters.favzw ? this.$store.getters.favzw : '';
			}
		},
		mounted() {
			this.getFavzw()
		},
		watch: {},
		created() {
			let that = this;
			
		},
		methods: {
			...mapActions(['LogSetSearchtimes','LogSetPhone','LogSetOpenid','LogSetName','LogSetPage','LogSetFavzw']),
			getFavzw(){
				let that = this
				let fZw = that.favzw
				
				fZw.map((item,index) => {
					let s = item.split('-')
					let y = s[0]
					let w = s[1]
					let l = that.linkList.filter(q => q.year == y)[0].link
					that.getZwDetail(l,w,index,y)
				})
				
			},
			getZwDetail(link,w,index,y){
				let that = this
				uni.request({
					url: link,
					method: 'get',
					dataType: 'text',
					data: {
						sstimes: new Date()
					},
					success: function(res) {
						var resjson = JSON.parse(res.data);
						that.filterZw(resjson,w,index,y)
					}
				});
			},
			filterZw(zw,w,index,y){
				let that = this
				let fzw = zw.filter(item => item.wyz == w)
				let z = fzw[0]
				z.year = y
				z.ggxx = y + '年黑龙江公务员考试'
				that.zwDetail.push(z)
				// that.$set(that.zwDetail,index,z)
				if(index == that.favzw.length - 1){
					that.gjp = false
				}
			},
			showToast(type, info) {
				this.$refs.uToast.show({
					type: type,
					icon: false,
					title: '失败主题',
					message: info,
				})
			},
			open(e) {
				let that = this
			},
			imgView(imgUrl) {
				wx.previewImage({
					urls: [imgUrl], //需要预览的图片http链接列表，注意是数组
					current: '', // 当前显示图片的http链接，默认是第一个
					success: function(res) {},
					fail: function(res) {},
					complete: function(res) {}
				});
			},
			
			showJzb(jfrs,zkrs){
				let jzb = jfrs / zkrs
				jzb % 1 === 0 ? jzb = jzb : jzb = jzb.toFixed(2)
				return jzb
			}
		},
		components: {}
	};
</script>

<style lang="scss">
	@import url(./index.css);
</style>
